package com.apes.scm.demo.service;

import com.apes.framework.plugin.esb.api.SimpleRequest;
import com.apes.framework.api.SpringManager;
import com.apes.oap.annotation.NeedInSessionType;
import com.apes.oap.annotation.ServiceMethod;
import com.apes.oap.annotation.ServiceMethodBean;
import com.apes.oap.response.OapResponse;
import com.apes.scm.demo.model.Person1;
import com.apes.scm.demo.repository.Person1Repository;
import org.springframework.transaction.annotation.Transactional;

@ServiceMethodBean(version = "1.0", needInSession = NeedInSessionType.NO)
public class AppSecretService {

    @Transactional()
    @ServiceMethod(method = "appSecret.save")
    public OapResponse<String> save(SimpleRequest request) {
        Person1Repository repository = SpringManager.getBean(Person1Repository.class);
        for (int i = 0; i <= 10; i++) {
            Person1 user = new Person1("userName" + String.valueOf(i));
            repository.save(user);
            if (i == 7) throw new RuntimeException("事务测试！");
        }
        return new OapResponse<String>().setBody("OK");
    }
}
